﻿using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;

namespace CharacterCreation.Business.ViewModels
{
    [Description("Special")]
    public class VMSpecial : ViewModelBase
    {
        [Required(ErrorMessage = "The name of the special is required")]
        [StringLength(50, MinimumLength = 3)]
        [Display(Name = "Special name")]
        public string Name { get; set; }

        [Display(Name = "Description")]
        [DataType(DataType.MultilineText)]
        public string Description { get; set; }

        [Display(Name = "Priority point cost")]
        public int PriorityPoints { get; set; }

        [Display(Name = "Special category")]
        public SpecialCategory Category { get; set; }

        public string CategoryDisplay
        {
            get
            {
                return ((DescriptionAttribute)typeof(SkillCategory)
                    .GetField(this.Category.ToString())
                    .GetCustomAttributes(typeof(DescriptionAttribute), false)
                    .First())
                    .Description;
            }
        }

        public string StatisticsDisplay
        {
            get
            {
                StringBuilder builder = new StringBuilder();
                if (this.Strength) builder.Append(" str");
                if (this.Dexterity) builder.Append(" dex");
                if (this.Fighting) builder.Append(" fig");
                if (this.Constitution) builder.Append(" con");
                if (this.Perception) builder.Append(" per");
                if (this.Intelligence) builder.Append(" int");
                if (this.WillPower) builder.Append(" will");
                if (this.Charisma) builder.Append(" cha");

                var result = builder.ToString().Replace(' ', '/');
                if (result.StartsWith("/")) result = result.Remove(0, 1);
                return result;
            }
        }


        public string Statistics
        {
            get
            {
                StringBuilder builder = new StringBuilder();
                if (this.Strength) builder.Append("str");
                if (this.Dexterity) builder.Append("dex");
                if (this.Fighting) builder.Append("fig");
                if (this.Constitution) builder.Append("con");
                if (this.Perception) builder.Append("per");
                if (this.Intelligence) builder.Append("int");
                if (this.WillPower) builder.Append("will");
                if (this.Charisma) builder.Append("cha");

                return builder.ToString();
            }
            set
            {
                value = value.ToLower();
                this.Strength = value.Contains("str");
                this.Dexterity = value.Contains("dex");
                this.Fighting = value.Contains("fig");
                this.Constitution = value.Contains("con");
                this.Perception = value.Contains("per");
                this.Intelligence = value.Contains("int");
                this.WillPower = value.Contains("will");
                this.Charisma = value.Contains("cha");
            }
        }

        public bool Strength { get; set; }
        public bool Dexterity { get; set; }
        public bool Fighting { get; set; }
        public bool Constitution { get; set; }
        public bool Perception { get; set; }
        public bool Intelligence { get; set; }
        [Display(Name = "Will power")]
        public bool WillPower { get; set; }
        public bool Charisma { get; set; }

    }
}
